import Vue from 'vue'
import Vuex from 'vuex'

import app from './modules/app'
import user from './modules/user'

import supplier from '@/api/supplier.js'
import product from '@/api/product.js'

// default router permission control
import permission from './modules/permission'

// dynamic router permission control (Experimental)
// import permission from './modules/async-router'
import getters from './getters'

Vue.use(Vuex)

export default new Vuex.Store({
  modules: {
    app,
    user,
    permission
  },
  state: {
    goods_type:'',
    goods_detail_tab_index:1,
    proudct_id:'',
    order_id:'',
    supplierList:[],
    flag:'',
    spectList:[{channel_price: "99.00",
      color: "",
      createtime: 1626343499,
      distribution_price: "99.00",
      id: 1,
      name: "中",
      proudct_id: 5,
      proudct_name: "足浴优惠券满200减30",
      quota: 99,
      set_num: 10,
      specs: "",
      stock: 11110,
      trade_price: "99.00",
      unified_price: "99.00"}],
    categoryList:[],
    typeList:[],
  },
  mutations: {
    SET_ORDER_ID: (state, data) => {
      state.order_id = data
    },
    SET_GOODS_TYPE: (state, data) => {
      state.goods_type = data
      console.log("state.goods_type",data)
    },
    SET_PROUDCT_ID: (state, data) => {
      console.log('proudct_id',data)
      state.proudct_id = data
    },
    SET_GOODS_DETAIL_TAB_INDEX: (state, data) => {
      state.goods_detail_tab_index = data
    },
    SET_SUPPLIER_LIST: (state, data) => {
      state.supplierList = data
    },
    SET_FLAG: (state, data) => {
      state.flag = data
    },
    SET_SPECTLIST: (state, data) => {
      state.spectList = data
    },
    SET_CATEGORY_LIST: (state, data) => {
      state.categoryList = data
      console.log("SET_CATEGORY_LIST",data)
    },
    SET_TYPE_LIST: (state, data) => {
      state.typeList = data
      console.log("SET_typeList",data)
    },
  },
  actions: {
    SET_TYPE_LIST ({ commit }, data) {
      commit('SET_TYPE_LIST',data);
    },
    SET_SPECTLIST ({ commit }, data) {
      commit('SET_SPECTLIST',data);
    },
    SET_FLAG ({ commit }, data) {
      commit('SET_FLAG',data);
    },
    SET_SUPPLIER_LIST ({ commit }, data) {
      commit('SET_SUPPLIER_LIST',data);
    },
    SET_ORDER_ID ({ commit }, data) {
      commit('SET_ORDER_ID',data);
    },
    SET_GOODS_TYPE ({ commit }, data) {
      commit('SET_GOODS_TYPE',data);
    },
    SET_PROUDCT_ID ({ commit }, data) {
      commit('SET_PROUDCT_ID',data);
    },
    SET_GOODS_DETAIL_TAB_INDEX: ({ commit }, data) => {
      commit('SET_GOODS_DETAIL_TAB_INDEX',data);
    },
    //获取商品分类
    GET_CATEGORY_LIST ({ commit }, params) {
      return new Promise((resolve, reject) => {
        product.CategoryRecursion(params).then(res => {
          const result = res.data
          commit('SET_CATEGORY_LIST', result)
          resolve(result)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 获取供应商列表
    GET_SUPPLIER_PAGE ({ commit }, params) {
      return new Promise((resolve, reject) => {
        console.log('params',params)
        // console.log('SupplierPage',supplier.SupplierPage)
        supplier.SupplierPage(params).then(res => {
          console.log('-------------res------------', res)
          const result = res.data.data
          commit('SET_SUPPLIER_LIST', result)
          resolve(result)
        }).catch(error => {
          reject(error)
        })
      })
    },
  },
  getters
})
